  var number = 0;
  var money = 0;
  var onOff = true;//是否可以下注
  var wanArr = [],
      qianArr = [],
      baiArr = [],
      shiArr = [],
      geArr = [],
      playTypes = null,
      content = '',
      arr1 = [],
      arr2 = [],
      arr3 = [];
  var playType = null;//下注方式
  var lotteryArr = [];//购彩内容
  var ding = null; //记录二字、三字定位
  $('#elem_jscq div').click(function(){
    $(this).siblings().removeClass('hover');
    $(this).addClass('hover');
    var index = $(this).index();
    lotteryArr = [];
    onOff = true;
    ding = null; //每次进来清空

    if($(this).text() == '二字组合'){
      playType = 'q3_ezzh'
    }else if($(this).text() == '三字组合'){
      playType = 'q3_szzh'
    }else if($(this).text() == '组选三'){
      playType = 'q3_zx3'
    }else if($(this).text() == '组选六'){
      playType = 'q3_zx6'
    }
    else if($(this).text() == '二字定位'){
      ding = 'ezdw'
    }else if($(this).text() == '三字定位'){
      playType = 'q3_szdw';
      ding = 'szdw'
    }
    
    $('.common .list').eq(index).show().siblings().hide();
    number = 0;
    money = 0;
    $('#zhu').text(0);
    $('#money').text(0)
  })
  // 彩种下的方式切换
  $('.erzu .tag,.sanzu .tag,.zusan .tag,.zuliu .tag').click(function(){
    $('.erzu .tag,.sanzu .tag,.zusan .tag,.zuliu .tag').removeClass('hover')
    $(this).addClass('hover');
    $('.bifa-m span').removeClass('hover');

    playType = $(this).data('type');
    // console.log(playType)
    number = 0;
    money = 0;
    $('#zhu').text(0);
    $('#money').text(0);
    lotteryArr = [];
  })
  
  // 三字定位切换
  $('.sanzi .tag').click(function(){
    $('.sanzi .tag').removeClass('hover');
    $(this).addClass('hover');
    $('.bifa-m span').removeClass('hover');
    number = 0;
    money = 0;
    $('#zhu').text(0);
    $('#money').text(0);
    lotteryArr = [];

    var val = $(this).text();
    if(val == '前三'){
      $('.sanzi .wei')[0].innerText= '万位';
      $('.sanzi .wei')[1].innerText= '千位';
      $('.sanzi .wei')[2].innerText= '百位';
      playType = 'q3_szdw';
      arr1 = [],
      arr2 = [],
      arr3 = [];
    }else if(val == '中三'){
      $('.sanzi .wei')[0].innerText= '千位';
      $('.sanzi .wei')[1].innerText= '百位';
      $('.sanzi .wei')[2].innerText= '十位';
      playType = 'z3_szdw';
      arr1 = [],
      arr2 = [],
      arr3 = [];
    }else if(val == '后三'){
      $('.sanzi .wei')[0].innerText= '百位';
      $('.sanzi .wei')[1].innerText= '十位';
      $('.sanzi .wei')[2].innerText= '个位';
      playType = 'h3_szdw';
      arr1 = [],
      arr2 = [],
      arr3 = [];
    }
    // console.log(playType)
  })
  // 选择下注

  $('.bifa-m span').click(function(){
    $(this).toggleClass('hover');
       
    if(!$(this).data('type')){//
      
      if(ding == 'ezdw'){//二字定位
        
        if( $(this).data('index') == 'wan' ){
          if($(this).hasClass('hover')){
            wanArr.push($(this).data('content'))
          }else{
            wanArr.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'qian'){
          if($(this).hasClass('hover')){
            qianArr.push($(this).data('content'))
          }else{
            qianArr.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'bai'){
          
          if($(this).hasClass('hover')){
            baiArr.push($(this).data('content'))
          }else{
            baiArr.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'shi'){
          if($(this).hasClass('hover')){
            shiArr.push($(this).data('content'))
          }else{
            shiArr.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'ge'){
          if($(this).hasClass('hover')){
            geArr.push($(this).data('content'))
          }else{
            geArr.pop($(this).data('content'))
          }
        }

        lotteryArr = [];
        for(var i= 0,iL=wanArr.length;i<iL;i++){ //万千
          for(var j= 0,jL=qianArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'wq_ezdw';
            content = wanArr[i]+','+qianArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=qianArr.length;i<iL;i++){//千百
          for(var j= 0,jL=baiArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'qb_ezdw';
            content = qianArr[i]+','+baiArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=wanArr.length;i<iL;i++){ //万百
          for(var j= 0,jL=baiArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'wb_ezdw';
            content = wanArr[i]+','+baiArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=wanArr.length;i<iL;i++){ //万十
          for(var j= 0,jL=shiArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'ws_ezdw';
            content = wanArr[i]+','+shiArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=wanArr.length;i<iL;i++){ //万个
          for(var j= 0,jL=geArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'wg_ezdw';
            content = wanArr[i]+','+geArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=qianArr.length;i<iL;i++){ //千十
          for(var j= 0,jL=shiArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'qs_ezdw';
            content = qianArr[i]+','+shiArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=qianArr.length;i<iL;i++){ //千个
          for(var j= 0,jL=geArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'qg_ezdw';
            content = qianArr[i]+','+geArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=baiArr.length;i<iL;i++){ //百十
          for(var j= 0,jL=shiArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'bs_ezdw';
            content = baiArr[i]+','+shiArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=baiArr.length;i<iL;i++){ //百个
          for(var j= 0,jL=geArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'bg_ezdw';
            content = baiArr[i]+','+geArr[j];
            calcu(playTypes,content)
          }
        }
        for(var i= 0,iL=shiArr.length;i<iL;i++){ //十个
          for(var j= 0,jL=geArr.length;j<jL;j++){
            onOff = false;
            playTypes = 'sg_ezdw';
            content = shiArr[i]+','+geArr[j];
            calcu(playTypes,content)
          }
        }

        $('#zhu').text((wanArr.length*qianArr.length)+(wanArr.length*baiArr.length)+(wanArr.length*shiArr.length)+(wanArr.length*geArr.length)+(qianArr.length*baiArr.length)+(qianArr.length*shiArr.length)+(qianArr.length*geArr.length)+(baiArr.length*shiArr.length)+(baiArr.length*geArr.length)+(shiArr.length*geArr.length));
        $('#money').text($('#zhu').text()*2);
        
        function calcu(playTypes,content){
          var lotterObj = {
              playType:playTypes,
              content:content,
              odds:$('i',this).text(),
              payPrice:2,
              times:1
            }
            lotteryArr.push(lotterObj);
            $('.content').data('content',lotteryArr)
        }
      }else if(ding == 'szdw'){ //三字定位
        
        if( $(this).data('index') == 'qs' ){
          if($(this).hasClass('hover')){
            arr1.push($(this).data('content'))
          }else{
            arr1.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'zs'){
          if($(this).hasClass('hover')){
            arr2.push($(this).data('content'))
          }else{
            arr2.pop($(this).data('content'))
          }
        }else if($(this).data('index') == 'hs'){
          
          if($(this).hasClass('hover')){
            arr3.push($(this).data('content'))
          }else{
            arr3.pop($(this).data('content'))
          }
        }
        lotteryArr = [];

        for(var i= 0,iL=arr1.length;i<iL;i++){ 
          for(var j= 0,jL=arr2.length;j<jL;j++){
            for(var k = 0,kL = arr3.length;k<kL;k++){

              content = arr1[i]+','+arr2[j]+','+arr3[k];
              var lotterObj = {
                playType:playType,
                content:content,
                odds:$('i',this).text(),
                payPrice:2,
                times:1
              }
            lotteryArr.push(lotterObj);
            $('.content').data('content',lotteryArr)
            }
          }
        }
        
        $('#zhu').text(arr1.length*arr2.length*arr3.length)
        $('#money').text($('#zhu').text()*2)

      }else{
        var lotterObj = {
            playType:playType,
            content:String($(this).data('content')),
            odds:$('i',this).text(),
            payPrice:2,
            times:1
          }
        lotteryArr.push(lotterObj);
        $('.content').data('content',lotteryArr)
        number++;
        money+=2;
        $('#zhu').text(number);
        $('#money').text(money);
      }

    }else{
      
      var lotterObj = {
        playType:$(this).data('type'),
        content:String($(this).data('content')),
        odds:$('i',this).text(),
        payPrice:2,
        times:1
      }

      if($(this).hasClass('hover')){
        lotteryArr.push(lotterObj);
        number++;
        money+=2;
      }else{
        lotteryArr.pop(lotterObj);
        number--;
        money-=2;
      }
      $('#zhu').text(number);
      $('#money').text(money);
      $('.content').data('content',lotteryArr) //记录下注信息
    }
    
    // console.log(lotteryArr)
  })
  
  // 重置
  $('.reset').click(function(){
    number = 0;
    money = 0;
    $('#zhu').text(0);
    $('#money').text(0);
    $('.bifa-m span').removeClass('hover');
    lotteryArr = []
  })

  // 下注
var buyObj = jsonObj;
var uid = getCookie('uid');
$('.action').click(function(){
  // console.log(lotteryArr)

  if(lotteryArr.length>0){
    
    layer.open({
      type: 2,
      area: ['600px', '400px'],
      fixed: false, //不固定
      maxmin: true,
      content: './action.html',
      end:function(){
        lotteryArr = [];
        number = 0;
        money = 0;
        $('#zhu').text(0);
        $('#money').text(0);
        $('.bifa-m span').removeClass('hover');
      }
    });
    
  }else{
    layer.msg('请选择你要投注的内容');
  }
  
})
// 历史走势
$('#tendency').click(function(){
  layer.open({
    type: 2,
    area: ['600px', '400px'],
    fixed: false, //不固定
    maxmin: true,
    content: './trend.html'
  })
})
// 视频
$('#video').click(function(){
  layer.msg('敬请期待');
})
  
// 时时彩两面盘赔率
function lmps(lmp){
  $('.pan-list span i')[0].innerText = lmp.zh
  $('.pan-list span i')[1].innerText = lmp.zh
  $('.pan-list span i')[2].innerText = lmp.zh
  $('.pan-list span i')[3].innerText = lmp.zh
  $('.pan-list span i')[4].innerText = lmp.loong
  $('.pan-list span i')[5].innerText = lmp.hu
  $('.pan-list span i')[6].innerText = lmp.he
}
// 时时彩1-5球赔率
function dyqddwqs(dyqddwq){
  $('.qiu-list span i').text(dyqddwq.sz0d9);
  $('.qiu .pour span i').text(dyqddwq.dxds)
}
// 时时彩前中后赔率
function qzhs(qzh){

  $('.qian-list').eq(0).find('span i')[0].innerText = qzh.bz
  $('.qian-list').eq(0).find('span i')[1].innerText = qzh.sz
  $('.qian-list').eq(0).find('span i')[2].innerText = qzh.dz
  $('.qian-list').eq(0).find('span i')[3].innerText = qzh.bz
  $('.qian-list').eq(0).find('span i')[4].innerText = qzh.zl
  
  $('.qian-list').eq(1).find('span i')[0].innerText = qzh.bz
  $('.qian-list').eq(1).find('span i')[1].innerText = qzh.sz
  $('.qian-list').eq(1).find('span i')[2].innerText = qzh.dz
  $('.qian-list').eq(1).find('span i')[3].innerText = qzh.bz
  $('.qian-list').eq(1).find('span i')[4].innerText = qzh.zl

  $('.qian-list').eq(2).find('span i')[0].innerText = qzh.bz
  $('.qian-list').eq(2).find('span i')[1].innerText = qzh.sz
  $('.qian-list').eq(2).find('span i')[2].innerText = qzh.dz
  $('.qian-list').eq(2).find('span i')[3].innerText = qzh.bz
  $('.qian-list').eq(2).find('span i')[4].innerText = qzh.zl
}
// 时时彩一字组合赔率
function yzzhs(yzzh){
  $('.yizu-list span i').text(yzzh.qszshs);
  $('.qw span i').text(yzzh.qw)
}
// 时时彩二字组合赔率
function ezzhs(ezzh){
  $('.erzu-list span i').text(ezzh.qy);
  $('.erzu-list span.dz i').text(ezzh.dz);
}
// 时时彩三字组合赔率
function szzhs(szzh){
   $('.sanzu-list span i').text(szzh.qy);
   $('.sanzu-list span.dz i').text(szzh.dz);
   $('.sanzu-list span.sth i').text(szzh.sth);
}
// 时时彩二字定位赔率
function ezdws(ezdw){
  $('.erzi-list span i').text(ezdw); 
}
// 时时彩三字定位赔率
function szdws(szdw){
  $('.sanzi-list span i').text(szdw); 
}
// 时时彩组选三赔率
function zxss(zxs){
  $('.zusan-list span i').text(zxs); 
}
// 时时彩组选六赔率
function zxls(zxl){
  $('.zuliu-list span i').text(zxl); 
}
// 时时彩跨度赔率
function kds(kd){
  var len = kd.length;
  for(var i= 0;i<len;i++){
      for(var j = 0;j<3;j++){
          $('.kuadu-list').eq(j).find('span i')[i].innerText = kd[i];
      }
  }
}
// 时时彩和数赔率
function hss(hs){
  $('.heshu-list span i').text(hs); 
}

function init (type){
  var obj = jsonObj;
  obj.type = type;//重庆时时彩
  
  $ajax(
    url+'dead_awar',
    'post',
    obj,
    function(data){
      
      var countDown = data.data.countDown;//彩票信息
 
      $('#lotteryName').text(countDown.lotteryName);//中文名称
      $('#lotteryName').data('type',countDown.lotteryType);//存储彩种类型

      $('#issue').text(countDown.issue);
      if(countDown.status == -1){
        $('#status').text('已关盘')
      }else if(countDown.status == 0){
        $('#status').text('已封盘')
        $('.alert-sec-circle').css('border','5px solid red');
        
      }else if(countDown.status == 1){
        $('#status').text('离封盘')
        // 赔率
        var oddsData = data.data.oddsData;
        var lmp = oddsData.lmp;//两面盘
        lmps(lmp);

        var dyqddwq = oddsData.dyqddwq//1-5球
        dyqddwqs(dyqddwq);

        var qzh = oddsData.qzh//前中后
        qzhs(qzh)

        var yzzh = oddsData.yzzh//一字组合
        yzzhs(yzzh)

        var ezzh = oddsData.ezzh//二字组合
        ezzhs(ezzh)
        
        var szzh = oddsData.szzh//三字组合
        szzhs(szzh)
        
        var ezdw = oddsData.ezdw//二字定位
        ezdws(ezdw)
        
        var szdw = oddsData.szdw//三字定位
        szdws(szdw)
        
        var zxs = oddsData.zxs//组选三
        zxss(zxs)
        
        var zxl = oddsData.zxl//组选六
        zxls(zxl)
        
        var kd = oddsData.kd//跨度
        kds(kd)

        var hs = oddsData.hs//和数
        hss(hs)

      }
      resetTime(countDown.countDown,$('#deadline'))//封盘倒计时

      var openResult = data.data.openResult;//上期开奖
      
      $('#prevGameNo').text(openResult.issue);
      var numberArry = openResult.number.split(',');//开奖号码
      
      var res = '';
      for(var i = 0,iL = numberArry.length;i<iL;i++){
        res += '<span class="number">'+numberArry[i]+'</span>'
      }
      $('#draw').html(res)

      
    },
    function(data){
      layer.msg(data.msg);
    }
  )

  // 开奖结果
  obj.rows = 10;
  obj.page = 1;
  $ajax(
    url+'lott_list',
    'post',
    obj,
    function(data){

      var list = data.data;
      var numberArr = list[1].number.split(',')
      var res = '';
      for(var i = 0,iL = list.length;i<iL;i++){
        
        res += '<ul class="ssc double_bg">'+
                  '<li>'+
                    '<div class="qi">'+
                      ''+list[i].issue.slice(-3)+'<font class="qiZiColor">期</font>'+
                    '</div>';
        if(list[i].number !== null){
          for(var j = 0,jL=numberArr.length;j<jL;j++){
            res+='<div class="num">'+list[i].number.split(',')[j]+'</div>'
                
          }
        }
        res += '</li>'+
              '</ul>'
            
      }
      $('#results').html(res)
    },
    function(data){
      layer.msg(data.msg);
    }
  )

  // 公告
  var uid = getCookie('uid');
  obj.count = 5;
  obj.uid = uid;
  
  $ajax(
    url+'message',
    'post',
    obj,
    function(data){
      
      var messageArr = data.data
      
      var mess = '';
      for(var i = 0,iL=messageArr.length;i<iL;i++){
        mess+='<li >'+
            '<a href="'+messageArr[i].url+'" class="a">'+messageArr[i].title+'</a>'+
            '<span class="date">'+messageArr[i].pubdate.split(' ')[0]+'</span>'+
          '</li>'
      }
      $('#notice').html(mess)
    },
    function(data){
      clearCookie('uid')
      layer.msg(data.msg);
    }
  )
}

